<?php
class RbacCommand extends CConsoleCommand
{
	private $_authManager;
	
        public function getHelp()
	{
		return <<<EOD
USAGE
            rbac huppeldepup
DESCRIPTION
            This command generates an initial RBAC authorization hierarchy.
EOD;
	}
	/**
	* Execute the action.
	* @param array command line parameters specific for this command
	*/
	public function run($args)
	{
		//ensure that an authManager is defined as this is mandatoryfor creating an auth heirarchy
		if(($this->_authManager=Yii::app()->authManager)===null)
		{
			echo "Error: an authorization manager, named 'authManager'
			must be configured to use this command.\n";
			echo "If you already added 'authManager' component in
			application configuration,\n";
			echo "please quit and re-enter the yiic shell.\n";
			return;
		}
		//provide the oportunity for the use to abort the request
		echo "This command will delete all roles. OK? [y/n]\n";
		//check the input from the user and continue if they indicated yes to the above question
		if(!strncasecmp(trim(fgets(STDIN)),'y',1))
		{
		//first we need to remove all operations, roles, child relationship	and assignments
			$this->_authManager->clearAll();
			echo "Authorization hierarchy successfully deleted.";
		}
	}
}
?>